package com.android.SchoolManagerSystem;

import android.view.View;
import android.view.ViewGroup;

public class PageManager {
	final public static int PAGE_LOGIN = 0;
	final public static int PAGE_OPERATELIST = PAGE_LOGIN + 1;
	final public static int PAGE_MYCENTER = PAGE_OPERATELIST + 1;
	final public static int PAGE_SCOREQUERY = PAGE_MYCENTER + 1;
	final public static int PAGE_SCOREINFO = PAGE_SCOREQUERY + 1;
	final public static int PAGE_ONLINECURRICULA = PAGE_SCOREINFO + 1;
	final public static int PAGE_PRACTIVE = PAGE_ONLINECURRICULA + 1;
	final public static int PAGE_JOBINFO = PAGE_PRACTIVE + 1;
	
	final public static int PAGE_STATIONMAIL = PAGE_JOBINFO + 1;
	final public static int PAGE_COMMONRESLIST = PAGE_STATIONMAIL + 1;
	final public static int PAGE_CSPW = PAGE_COMMONRESLIST + 1;
	final public static int PAGE_BEDROOM = PAGE_CSPW + 1;
	final public static int PAGE_JWXT = PAGE_BEDROOM + 1;
	final public static int PAGE_TEACHERNAV = PAGE_JWXT + 1;
	final public static int PAGE_STRNAV = PAGE_TEACHERNAV + 1;
	final public static int PAGE_MAINNAV = PAGE_STRNAV + 1;
	final public static int PAGE_JWWEB = PAGE_MAINNAV + 1;
	final public static int PAGE_DGWEB = PAGE_JWWEB + 1;
	
	

	private static ViewGroup mRootView = null;
	final private static int PAGE_ROOT = PAGE_OPERATELIST;
	private static int mCurrentPage = PAGE_LOGIN;

	public static void setRootView(ViewGroup rootView) {
		mRootView = rootView;
	}

	public static void changeToRootPage() {
		// View page = mRootView.findViewById(R.id.main_sc);
		// page.setVisibility(View.VISIBLE);
		if(SchoolManagerSystem.strUserType == "2")
			changeToPage(PAGE_TEACHERNAV);
		else
			changeToPage(PAGE_STRNAV);
	}

	public static boolean isRootPage() {
		return mCurrentPage == PAGE_ROOT ? true : false;
	}

	public static boolean isLoginPage() {
		return mCurrentPage == PAGE_LOGIN ? true : false;
	}

	public static void changeToPage(int newPage) {
		int nResID = getPageResID(newPage);
		if (nResID != 0) {
			hideCurrentPage();
			View page = mRootView.findViewById(nResID);
			page.setVisibility(View.VISIBLE);

			mCurrentPage = newPage;
		}
	}

	private static int getPageResID(int page) {
		int nResID = 0;

		switch (page) {
		case PAGE_OPERATELIST: {
			nResID = R.id.operaterlist;
		}
			break;

		case PAGE_MYCENTER: {
			nResID = R.id.mycenter;
		}
			break;

		case PAGE_SCOREQUERY: {
			nResID = R.id.scorequery;
		}
			break;
		case PAGE_JWWEB:{
			nResID = R.id.jwwebpage;
		}
		break;
		case PAGE_SCOREINFO: {
			nResID = R.id.scoreinfo;
		}
			break;
		case PAGE_DGWEB:{
			nResID = R.id.commdgwebpage;
		}
		break;

		case PAGE_ONLINECURRICULA: {
			nResID = R.id.onlinecurricula;
		}
			break;
		case PAGE_STRNAV: {
			//
			nResID = R.id.stu_nav_bg;
		}
			break;
		case PAGE_MAINNAV:
		{
			nResID = R.id.nav_main;
		}
		break;

		case PAGE_JOBINFO: {
			nResID = R.id.jobinfo;
		}
			break;

		case PAGE_STATIONMAIL: {
			nResID = R.id.stationmail;
		}
			break;

		case PAGE_LOGIN: {
			nResID = R.id.loginpage;
		}
			break;
		case PAGE_TEACHERNAV: {
			nResID = R.id.main_sc_list;
		}
			break;
		case PAGE_COMMONRESLIST: {
			nResID = R.id.commonreslist;
		}
			break;
		case PAGE_CSPW: {
			nResID = R.id.cspwdetail;
		}
			break;
		case PAGE_BEDROOM: {
			nResID = R.id.bedroom;
		}
			break;
		case PAGE_JWXT: {
			nResID = R.id.jiaowxt;
		}
			break;
		}

		return nResID;
	}

	private static void hideCurrentPage() {
		if (mCurrentPage == PAGE_ROOT) {
			return;
		}

		int nResID = getPageResID(mCurrentPage);
		if (nResID != 0) {
			View page = mRootView.findViewById(nResID);
			page.setVisibility(View.INVISIBLE);
		}
	}
}